{include file="public/header"}
<body>
	<div class="sectionY">
		<a href="javascript:history.back();">
			<img src="__PUBLIC__/home/images/a19.png" alt="" class="a1">
		</a>
		<p class="p1">设置</p>
	</div>
	<div class="kong1" style=""></div>
	<div class="she_section1">
		<div class="f1 clearfix">
			<span class="s1" style="padding-top: 8px;">头像</span>
			<img src="{$user.avatar}" id="imghead" alt="" class="im2 pic_btn">
			<img src="__PUBLIC__/home/images/a39.png" alt="" class="im1" style="top: 20px;">
		</div>
		<input type="file" style="display: none" onchange="imgChange(this)">
		<div class="f1 clearfix">
			<a href="{:url('User/modify_nick')}">
				<span class="s1" >昵称</span>
				<span class="s2">{$user.nick_name}</span>
				<img src="__PUBLIC__/home/images/a39.png" alt="" class="im1">
			</a>
		</div>
		<div class="f1 clearfix">
			<a href="{:url('User/modify_password')}">
				<span class="s1" >密码</span>
				<span class="s2"></span>
				<img src="__PUBLIC__/home/images/a39.png" alt="" class="im1">
			</a>
		</div>
		<div class="f1 clearfix">
			<a href="">
				<span class="s1" >手机号</span>
				<span class="s2">{$user.mobile}</span>
				<img src="__PUBLIC__/home/images/a39.png" alt="" class="im1">
			</a>
		</div>
		<div class="f2">
			<a href="{:url('logout')}">退出登录</a>
		</div>
	</div>
	
</body>

<script>
	var is_app=0;
	try {
		is_app = android.getType();
	}catch (e) {

	}
	$(function(){
		$(".pic_btn").click(function(){
			if(is_app==1){
				android.uploadImage(location.origin+"/home/Upload/index.html");
			}else{
				$(this).parent().siblings("input").click();
			}
		});
	})
</script>
<script>
	//安卓回调
	function setImage(img_url) {
		$("#imghead").attr('src',img_url); // 修改img标签src属性值
		$.post("{:url('setAvatar')}", {img_url:img_url},function (res) {
			modal.msg(res.result_info);
		});
	}
	function imgChange(obj) {
		var docObj=$(obj).get(0);
		if (docObj.files && docObj.files[0]) {
			if(!/image\/\w+/.test(docObj.files[0].type)){
				//图片文件的type值为image/png或image/jpg
				layer.msg("文件必须为图片！");
				return false;
			}
			var formData = new FormData();
			formData.append("image",docObj.files[0]);
			$.ajax({
				url: "{:url('Upload/index')}",
				type: "POST",
				data: formData,
				/**
				 *必须false才会自动加上正确的Content-Type
				 */
				contentType: false,
				/**
				 * 必须false才会避开jQuery对 formdata 的默认处理
				 * XMLHttpRequest会对 formdata 进行正确的处理
				 */
				processData: false,
				success: function (rs) {
					if(rs.result_code=='0000'&&rs.result_data!=''){
						$("#image_url").val(rs.result_data);
						$("#imghead").attr('src',rs.result_data);
						setImage(rs.result_data);
					}else{
						layer.msg('图片有误请更换图片');
					}
				},
				error: function () {
					layer.msg('system error');
				}
			});
		} else {
			layer.msg('请上传图片');
		}
		return true;
	}
</script>

</html>